package com.swe727.spring2011.constraint1.client;

import java.rmi.RemoteException;

import com.swe727.spring2011.constraint1.client.util.LogUtil;
import com.swe727.spring2011.constraint1.coordinate.Coordinate;

public class ClientMedevacHandler implements ClientMedevacRemote {

	private final String NODE_ID;
	private int medevacReceivedCount;
	
	public ClientMedevacHandler(String nodeId) {
		NODE_ID = nodeId;
		medevacReceivedCount = 0;
	}
	
	@Override
	public void receiveMedevac(Coordinate coordinate) throws RemoteException {
		medevacReceivedCount++;
		
		long now = System.currentTimeMillis();
		System.out.println("Received medevac at " + now);
		long created = coordinate.getTimestamp().getTime();
		long latency = now - created;
		LogUtil.writeReceiveMedevacLatency(NODE_ID, latency);
	}

	@Override
	public int getMedevacReceivedCount() throws RemoteException {
		return medevacReceivedCount;
	}
}
